<?php
/**
 * Diy.php
* 跨境电商商城系统
 * =============================================
 * Copy right 2016-2026 大连熠泽科技网络有限公司
 * ---------------------------------------------
 * 官方网址: http://www.yizehuitong.com
 * =============================================
 * @author : yizehuitong
 * @date : 2019.10
 * @version : v2.0
 */

namespace app\wap\controller;

use data\service\Config as WebConfig;
use data\service\Member;


/**
 * 手机端自定义模板控制器
 */
class Diy extends BaseWap
{
	
	public function customTemplateIndex()
	{
		if ($this->custom_template_is_enable == 0) {
			// 没有开启自定义模板，跳转到首页
			$this->redirect(__URL(\think\Config::get('view_replace_str.APP_MAIN') . "/Index/index"));
		}
		$id = request()->get("id", 0);
		$config = new WebConfig();
		$member = new Member();
		$custom_template_info = $config->getFormatCustomTemplate($id);
		
		$this->assign("custom_template", $custom_template_info);
		
		// 首页优惠券
		$coupon_list = $member->getMemberCouponTypeList($this->instance_id, $this->uid);
		$this->assign('coupon_list', $coupon_list);
		
		// 公众号配置查询
		$wchat_config = $config->getInstanceWchatConfig($this->instance_id);
		
		$is_subscribe = 0; // 标识：是否显示顶部关注 0：[隐藏]，1：[显示]
		if ($this->web_info["is_show_follow"] == 1) {
			// 检查是否配置过微信公众号
			if (!empty($wchat_config['value'])) {
				if (!empty($wchat_config['value']['appid']) && !empty($wchat_config['value']['appsecret'])) {
					// 如何判断是否关注
					if (isWeixin()) {
						if (!empty($this->uid)) {
							// 检查当前用户是否关注
							$user_sub = $this->user->checkUserIsSubscribeInstance($this->uid);
							if ($user_sub == 0) {
								// 未关注
								$is_subscribe = 1;
							}
						}
					}
				}
			}
		}
		
		$this->assign("is_subscribe", $is_subscribe);
		
		// 手机端自定义模板底部菜单
		$this->getWapCustomTemplateFooter();
		
		// 公众号二维码获取
		$source_user_name = "";
		$source_img_url = "";
		$source_uid = request()->get('source_uid', '');
		if (!empty($source_uid)) {
			$_SESSION['source_uid'] = $source_uid;
			$user_info = $member->getUserInfoByUid($_SESSION['source_uid']);
			if (!empty($user_info)) {
				$source_user_name = $user_info["nick_name"];
				if (!empty($user_info["user_headimg"])) {
					$source_img_url = $user_info["user_headimg"];
				}
			}
		}
		
		// 首页公告
		$this->assign('source_user_name', $source_user_name);
		$this->assign('source_img_url', $source_img_url);
		
		return $this->view($this->style . 'CustomTemplate/customTemplateIndex');
	}
	
}